define([ "app", "jquery", "md5", "ecb", "resources/UserResource",
		"services/MenuService", "services/UserService",
		"resources/UploadResources" ], function(app) {

	var deps = [ "$scope", "UserResource", "$location", "UserService",
			"MenuService", "UploadResources" ];

	function controller($scope, UserResource, $location, UserService,
			MenuService, UploadResources) {

		$scope.uploadFile = function() {
			$scope.loading = true;
			var file = $('#textfield').val();
			var formData = new FormData(document.forms.namedItem("fileinfo"));

			if (file == null || file == "") {
				alert("请选中上传文件!");
				$scope.loading = false;
				return;
			} else if (file.indexOf('.xls') != -1
					|| file.indexOf('.xlsx') != -1) {
				var name = file.substring(file.lastIndexOf("\\") + 1);
				var type = $('#fileType').val();
				// 用户
				if (type == 1) {
					methodName = "user";
				}
				// 组织
				else {
					methodName = "org";
				}
				UploadResources.uploadFile(formData, name, methodName).success(
						function(data) {
							var json = eval('('+data.fileId+')');
							alert(json.result);
							$scope.loading = false;
						});
				$('#textfield').val("");
				$('#fileField').val("");
			} else {
				alert("请选中指定标准EXCEL格式!");
				$('#textfield').val("");
				$scope.loading = false;
				return;
			}
		};
	}

	controller.$inject = deps;
	app.lazy.controller("UploadController", controller);
});
